<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="../vue.js"></script>
    </head>

    <body>
        <div id="app">
            <input type="text" v-model="msg" />
            <br />
            <button @click="num++">自加{{num}}</button>
            <br />
            plus:{{plus}}
            <br />
            <input type="text" v-model="goodInfo.name" />{{goodInfo.name}}
        </div>
        <script>
            Vue.config.productionTip = false;

            const vm = new Vue({
                el: "#app",
                data() {
                    return {
                        msg: "",
                        num: 0,
                        goodInfo: {
                            name: "hauwei",
                            price: 1000,
                        },
                    };
                },
                computed: {
                    plus() {
                        return this.num + 2;
                    },
                },
                watch: {
                    msg(newVal, oldVal) {
                        console.log(
                            "msg现在的值为",
                            newVal,
                            "。之前的值为：",
                            oldVal
                        );
                    },
                    plus(newVal, oldVal) {
                        console.log("num加了2");
                    },
                    goodInfo: {
                        immediate: true,
                        deep: true,
                        handler(newVal, oldVal) {
                            console.log(
                                "goodInfo改变了",
                                newVal,
                                oldVal
                            );
                        },
                    },
                },
            });
        </script>
    </body>
</html>
